<template>
  <el-form class="right-event-link">
    <slider-normal v-if="isAutoLink" v-model="linkEvent.comps[3].attrs.delayTime" :min="0" :max="10" :step="1" label="自动关闭时间(s)" @change="onUpdateEvent"></slider-normal>
  </el-form>
</template>

<script>
import SliderNormal from '@/views/components/edit/SliderNormal.vue'

import { mapState, mapActions } from 'vuex'

  export default {
    components: {
      SliderNormal,
    },
    computed:{
      ...mapState({
        linkEvent: (state) => {
          if(state.components.currentComponentData){
            return _.cloneDeep(state.components.currentComponentData.events.link)
          }else{
            return _.cloneDeep(state.components.currentPage.events.link)
          }
        },
        isComp: (state) => state.components.currentComponentData ? true : false
      }),
      isAutoLink(){
        const event = this.linkEvent;
        if(event){
          return event.comps[3] && event.comps[3].attrs.value;
        }else{
          return false;
        }
      }
    },
    methods:{
      ...mapActions({
        updateEvent: "components/updateEvent",
        updatePageEvent: "components/updatePageEvent",
      }),
      onUpdateEvent() {
        const event = this.linkEvent;
        if(this.isComp){
          this.updateEvent({type:event.type, event});
        }else{
          this.updatePageEvent({type:event.type, event});
        }
      },
    }
  }
</script>